package br.edu.ufcg.dsc.compiladores.serializer;

import br.edu.ufcg.dsc.compiladores.services.PascalGrammarAccess;
import com.google.inject.Inject;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.AbstractElementAlias;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.AlternativeAlias;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.GroupAlias;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.TokenAlias;
import org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynNavigable;
import org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition;
import org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer;

@SuppressWarnings("all")
public class PascalSyntacticSequencer extends AbstractSyntacticSequencer {

	protected PascalGrammarAccess grammarAccess;
	protected AbstractElementAlias match_case_statement_SemicolonKeyword_5_q;
	protected AbstractElementAlias match_factor_NilKeyword_5_or_STRGTerminalRuleCall_3;
	protected AbstractElementAlias match_factor_NotKeyword_8_0_a;
	protected AbstractElementAlias match_factor_SIGNParserRuleCall_1_0_q;
	protected AbstractElementAlias match_factor_SIGNParserRuleCall_2_0_q;
	protected AbstractElementAlias match_field_list_SemicolonKeyword_1_1_q;
	protected AbstractElementAlias match_file_type_set_type___FileKeyword_0_OfKeyword_1___or___SetKeyword_0_OfKeyword_1__;
	protected AbstractElementAlias match_for_statement_DowntoKeyword_4_1_or_ToKeyword_4_0;
	protected AbstractElementAlias match_scale_factor_EKeyword_0_0_or_EKeyword_0_1;
	protected AbstractElementAlias match_structured_type_PackedKeyword_0_q;
	
	@Inject
	protected void init(IGrammarAccess access) {
		grammarAccess = (PascalGrammarAccess) access;
		match_case_statement_SemicolonKeyword_5_q = new TokenAlias(false, true, grammarAccess.getCase_statementAccess().getSemicolonKeyword_5());
		match_factor_NilKeyword_5_or_STRGTerminalRuleCall_3 = new AlternativeAlias(false, false, new TokenAlias(false, false, grammarAccess.getFactorAccess().getNilKeyword_5()), new TokenAlias(false, false, grammarAccess.getFactorAccess().getSTRGTerminalRuleCall_3()));
		match_factor_NotKeyword_8_0_a = new TokenAlias(true, true, grammarAccess.getFactorAccess().getNotKeyword_8_0());
		match_factor_SIGNParserRuleCall_1_0_q = new TokenAlias(false, true, grammarAccess.getFactorAccess().getSIGNParserRuleCall_1_0());
		match_factor_SIGNParserRuleCall_2_0_q = new TokenAlias(false, true, grammarAccess.getFactorAccess().getSIGNParserRuleCall_2_0());
		match_field_list_SemicolonKeyword_1_1_q = new TokenAlias(false, true, grammarAccess.getField_listAccess().getSemicolonKeyword_1_1());
		match_file_type_set_type___FileKeyword_0_OfKeyword_1___or___SetKeyword_0_OfKeyword_1__ = new AlternativeAlias(false, false, new GroupAlias(false, false, new TokenAlias(false, false, grammarAccess.getFile_typeAccess().getFileKeyword_0()), new TokenAlias(false, false, grammarAccess.getFile_typeAccess().getOfKeyword_1())), new GroupAlias(false, false, new TokenAlias(false, false, grammarAccess.getSet_typeAccess().getSetKeyword_0()), new TokenAlias(false, false, grammarAccess.getSet_typeAccess().getOfKeyword_1())));
		match_for_statement_DowntoKeyword_4_1_or_ToKeyword_4_0 = new AlternativeAlias(false, false, new TokenAlias(false, false, grammarAccess.getFor_statementAccess().getDowntoKeyword_4_1()), new TokenAlias(false, false, grammarAccess.getFor_statementAccess().getToKeyword_4_0()));
		match_scale_factor_EKeyword_0_0_or_EKeyword_0_1 = new AlternativeAlias(false, false, new TokenAlias(false, false, grammarAccess.getScale_factorAccess().getEKeyword_0_0()), new TokenAlias(false, false, grammarAccess.getScale_factorAccess().getEKeyword_0_1()));
		match_structured_type_PackedKeyword_0_q = new TokenAlias(false, true, grammarAccess.getStructured_typeAccess().getPackedKeyword_0());
	}
	
	@Override
	protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if(ruleCall.getRule() == grammarAccess.getDIRECTIVERule())
			return getDIRECTIVEToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getIDENTIFIERRule())
			return getIDENTIFIERToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getSIGNRule())
			return getSIGNToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getSTRGRule())
			return getSTRGToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getTag_fieldRule())
			return gettag_fieldToken(semanticObject, ruleCall, node);
		return "";
	}
	
	/**
	 * terminal DIRECTIVE:
	 * 	'forward'
	 * ;
	 */
	protected String getDIRECTIVEToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "forward";
	}
	
	/**
	 * terminal IDENTIFIER:
	 * 	LETTER (LETTER | DIGIT)*;
	 */
	protected String getIDENTIFIERToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "A";
	}
	
	/**
	 * SIGN:
	 * 	'+'|'-'
	 * ;
	 */
	protected String getSIGNToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "+";
	}
	
	/**
	 * terminal STRG:
	 * 	"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
	 * ;
	 */
	protected String getSTRGToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "\'\'";
	}
	
	/**
	 * tag_field:
	 * 	(IDENTIFIER ':')?
	 * ;
	 */
	protected String gettag_fieldToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "";
	}
	
	@Override
	protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) {
		if (transition.getAmbiguousSyntaxes().isEmpty()) return;
		List<INode> transitionNodes = collectNodes(fromNode, toNode);
		for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) {
			List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax);
			if(match_case_statement_SemicolonKeyword_5_q.equals(syntax))
				emit_case_statement_SemicolonKeyword_5_q(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_factor_NilKeyword_5_or_STRGTerminalRuleCall_3.equals(syntax))
				emit_factor_NilKeyword_5_or_STRGTerminalRuleCall_3(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_factor_NotKeyword_8_0_a.equals(syntax))
				emit_factor_NotKeyword_8_0_a(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_factor_SIGNParserRuleCall_1_0_q.equals(syntax))
				emit_factor_SIGNParserRuleCall_1_0_q(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_factor_SIGNParserRuleCall_2_0_q.equals(syntax))
				emit_factor_SIGNParserRuleCall_2_0_q(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_field_list_SemicolonKeyword_1_1_q.equals(syntax))
				emit_field_list_SemicolonKeyword_1_1_q(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_file_type_set_type___FileKeyword_0_OfKeyword_1___or___SetKeyword_0_OfKeyword_1__.equals(syntax))
				emit_file_type_set_type___FileKeyword_0_OfKeyword_1___or___SetKeyword_0_OfKeyword_1__(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_for_statement_DowntoKeyword_4_1_or_ToKeyword_4_0.equals(syntax))
				emit_for_statement_DowntoKeyword_4_1_or_ToKeyword_4_0(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_scale_factor_EKeyword_0_0_or_EKeyword_0_1.equals(syntax))
				emit_scale_factor_EKeyword_0_0_or_EKeyword_0_1(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_structured_type_PackedKeyword_0_q.equals(syntax))
				emit_structured_type_PackedKeyword_0_q(semanticObject, getLastNavigableState(), syntaxNodes);
			else acceptNodes(getLastNavigableState(), syntaxNodes);
		}
	}

	/**
	 * Syntax:
	 *     ';'?
	 */
	protected void emit_case_statement_SemicolonKeyword_5_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     STRG | 'nil'
	 */
	protected void emit_factor_NilKeyword_5_or_STRGTerminalRuleCall_3(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     'not'*
	 */
	protected void emit_factor_NotKeyword_8_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     SIGN?
	 */
	protected void emit_factor_SIGNParserRuleCall_1_0_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     SIGN?
	 */
	protected void emit_factor_SIGNParserRuleCall_2_0_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     ';'?
	 */
	protected void emit_field_list_SemicolonKeyword_1_1_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     ('set' 'of') | ('file' 'of')
	 */
	protected void emit_file_type_set_type___FileKeyword_0_OfKeyword_1___or___SetKeyword_0_OfKeyword_1__(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     'to' | 'downto'
	 */
	protected void emit_for_statement_DowntoKeyword_4_1_or_ToKeyword_4_0(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     'E' | 'e'
	 */
	protected void emit_scale_factor_EKeyword_0_0_or_EKeyword_0_1(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     'packed'?
	 */
	protected void emit_structured_type_PackedKeyword_0_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
}
